/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

/**
 *
 * @author Felipe Gutierrez
 */
import java.util.ArrayList;

import net.java.dev.greenbox.base.Attribute;
import net.java.dev.greenbox.base.Clazz;

import xmibase.XmiAttribute;
import xmibase.XmiClass;
import xmibase.XmiInterface;

public class EntityUtils extends FormatationUtils {

	public int soma(int x, int y) {
		return x + y;
	}

	public String getFetchGroup(ArrayList<XmiAttribute> attributes, String value) {
		String aux = "";

		for (int i = 0; i < attributes.size(); i++) {
			if ( (attributes.get(i).getAggregation() != null)) {
				if (attributes.get(i).getAggregation().equals(value)
						&& (i != attributes.size() - 1)) {
					aux += "@Persistent(name = \"" + attributes.get(i).getName()	+ "\" ),\n";

				} else if ((i == attributes.size() - 1)) {
					aux += "@Persistent(name = \"" + attributes.get(i).getName()	+ "\" )";
				}
			} else {
				if ((i != attributes.size() - 1)) {
					aux += "@Persistent(name = \"" + attributes.get(i).getName()	+ "\" ),\n";

				} else {
					aux += "@Persistent(name = \"" + attributes.get(i).getName()	+ "\" )";
				}
			}

		}

		return aux;
	}

	public final String getEntityClassGeneralization(XmiClass classe) {
		if (classe.getHasSuperClass()) {
			return "extends " + classe.getSuperClass().getName();
		} else {
			return "";
		}
	}

	public final String getEntityClassInterface(XmiClass classe) {


		if (classe.hasInterface()) {
			String aux = "implements ";

			ArrayList<XmiInterface> tmpInterfaces = classe.getInterfaces();
			int size = tmpInterfaces.size();
			for ( int i = 0; i < size; i++ ) {
				XmiInterface tmpInterface  = tmpInterfaces.get(i);

				if ( i != size -1 ) {
					aux += tmpInterface.getName() + ",";
				}else {
					aux += tmpInterface.getName();
				}
			}
			return aux;
		} else {
			return "";

		}
	}

	public String getInstanceList(ArrayList<XmiAttribute> attributes) {
		String output = "";
		for (XmiAttribute att : attributes) {

			if (att.getUpperMultiplicity() == -1) {
				output += att.getName() + "= new "
						+ "LinkedList<" + this.convertPrimitiveType(att.getDataType()) + ">();\n";
			}

		}

		return output;

	}
}
